﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace MebApp.Launcher
{

    public partial class AppBlock : ButtonBase, IButtonControl
    {
        private DialogResult m_DialogResult;
        private bool isDefault = false;
        bool mouseHover = false;
        bool buttonDown = false;
        public AppBlock()
        {
            InitializeComponent();
            this.MouseClick += AppBlock_MouseClick;
        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            mouseHover = true;
            if (buttonDown)
            {
                this.panel1.BorderStyle = BorderStyle.FixedSingle;
            }
            else
            {
                this.panel1.BorderStyle = BorderStyle.None;
            }
            base.OnMouseMove(e);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            mouseHover = false;
            this.panel1.BorderStyle = BorderStyle.None;
            base.OnMouseLeave(e);
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.Focus();
            buttonDown = true;
            this.BackColor = Color.Gray;
            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            buttonDown = false;
            if (mouseHover)
            {
                this.panel1.BorderStyle = BorderStyle.FixedSingle;
            }
            else
            {
                this.panel1.BorderStyle = BorderStyle.None;
            }
            base.OnMouseUp(e);
        }

        private void AppBlock_MouseClick(object sender, MouseEventArgs e)
        {
            throw new NotImplementedException();
        }

        public void NotifyDefault(bool value)
        {
            isDefault = value;
        }

        public void PerformClick()
        {
            base.OnClick(EventArgs.Empty);
        }

        public string AppName
        {
            get
            {
                return this.label1.Text;
            }
            set
            {
                this.label1.Text = value;
            }
        }
        public Image AppImage
        {
            get
            {
                if (this.pictureBox1.Image != null)
                    return (Image)this.pictureBox1.Image.Clone();
                return null;
            }
            set
            {
                this.pictureBox1.Image = value;
            }
        }

        public DialogResult DialogResult {
            get
            {
                return m_DialogResult;
            }
            set
            {
                m_DialogResult = value;
            }
        }
    }
}
